/**
* @Title: performanceStandard_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2015 
* Company:中国平安
*
* @Project HIMS-HCPMS
* @author EX-XIEQI001
* @date 2015年02月27日 上午11:06:02
* @version V1.0
*/

;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('PerformanceStandardCtrl', ['$scope', '$http','BaseURL', 
	                                       function($scope, $http,baseUrl){
		$scope.data = {
						"name": "医疗机构综合评价标准",
						"score": "100",
						"list": [
						         {
						        	 "name": "经济视角(控费)",
						        	 "score": "30",
						        	 "list": [
						        	          {"code": "1","name": "住院费用","score": "9"},
						        	          {"code": "2","name": "门诊费用","score": "9"},
						        	          {"code": "3","name": "FWA审核","score": "9"}
						        	          ]
						         },
                                 {
						        	 "name": "患者视角",
						        	 "score": "30",
						        	 "list": [
						        	          {"code": "4","name": "个人负担","score": "30"}
						        	          ]
						         },
                                 {
					        		 "name": "医保管理视角",
					        		 "score": "20",
					        		 "list": [
					        		          {"code": "5","name": "医保审核管理","score": "20"},
					        		          {"code": "6","name": "医保政策依从性","score": "20"}
					        		          ]
						         },
                                 {
						        	 "name": "创新与发展视角",
						        	 "score": "20",
						        	 "list": [
						        	          {"code": "7","name": "信息化","score": "20"}
						        	          ]
						         }
                                ]
						};
		/**
		 * 分析数据 在页面上展示
		 */
		function  analyticalData(data) {
			var length = data.list.length;
			if (length > 1) {
				data.twoWidth = parseFloat(100/length);
				data.oneWidth = parseFloat(100 - data.twoWidth);
				angular.forEach(data.list,function(twoData,i) {
					var threeLength = twoData.list.length;
					if (threeLength > 1) {
						twoData.fourWidth = parseFloat(100/threeLength);
						twoData.threeWidth = parseFloat(100 - twoData.fourWidth);
					}
					else {
						twoData.fourWidth = 100;
					}
				});
			}
			else {
				data.twoWidth =100;
			}
		}
		//调用
		analyticalData($scope.data);
		
		//存储已经请求过的指标值集合
		var kpiDataMap = {};
		
		//是否显示指标集合
		$scope.selectedShow = false;
		
		//三角形距离左边的位置
		$scope.beforeLeft = 8;
		
		$scope.afterLeft = 9;
		
		//点击事件
		$scope.selectData = function(data) {
			
			if ($scope.selectedShow == false) {
				$scope.selectedShow = true;
			}
			$scope.selectedData = data;
			angular.forEach($scope.data.list,function(twoData,i) {
				angular.forEach(twoData.list,function(threeData,j) {
					if (threeData == data) {
						//三角形跟随选中的三级树形移动
//						var offsetWidth = document.body.offsetWidth - 150;
//						var left = parseFloat(offsetWidth * $scope.data.twoWidth * i / 100) +
//						parseFloat(offsetWidth * $scope.data.twoWidth * twoData.fourWidth * (j + 0.5) / 10000);
//						if (i > 0 && j == 0) {
//							$scope.beforeLeft = parseFloat(left - 7).toFixed(2);
//							$scope.afterLeft = parseFloat(left - 6).toFixed(2);
//						}
//						else if (i > 0 && j == 1) {
//							$scope.beforeLeft = parseFloat(left - 10).toFixed(2);
//							$scope.afterLeft = parseFloat(left - 9).toFixed(2);
//						}
//						else if (i > 0 || (i >= 0 && j > 1)) {
//							$scope.beforeLeft = parseFloat(left - 15).toFixed(2);
//							$scope.afterLeft = parseFloat(left - 14).toFixed(2);
//						}
//						else {
//							$scope.beforeLeft = parseFloat(left).toFixed(2);
//							$scope.afterLeft = parseFloat(left + 1).toFixed(2);
//						}
						
						threeData.selected = true;
					}
					else {
						threeData.selected = false;
					}
				});
			});
			//获取展示指标数据
			if (kpiDataMap[data.code]) {
				$scope.kpiSelectedDatas = kpiDataMap[data.code];
			}
			else {
				//请求后台数据 请后续修改，暂时只做测试使用
				$scope.kpiSelectedDatas = test(data.code);
				kpiDataMap[data.code] = $scope.kpiSelectedDatas;
			}
		}
		//测试使用 后续可以删除
		function test(code) {
			if (code == 1) {
				return [
                        {"name": "次均住院费用增长率","score": "1"},
                        {"name": "住院实际发生的统筹支付费用超支率（或总支付费用超支率）","score": "1"},
                        {"name": "平均住院日","score": "1"},
                        {"name": "平均床日费","score": "1"},
                        {"name": "次均住院费用","score": "1"},
                        {"name": "人均药品费用","score": "1"},
                        {"name": "住院药占比","score": "1"},
                        {"name": "住院人均检查费用","score": "1"},
                        {"name": "住院检查费占比","score": "1"}
                        ];
			}
			else if (code == 2) {
				return [
                        {"name": "门诊目录内药品费用占比","score": "1"},
                        {"name": "门诊医保费用占比","score": "1"},
                        {"name": "门诊基本药物占比","score": "1"},
                        {"name": "使用总控指标比例","score": "1"},
                        {"name": "人均门诊费用增长率","score": "1"},
                        {"name": "门诊人均费用","score": "1"}
                        ];
			}
			else if (code == 3) {
				return [
                        {"name": "违规费用占比","score": "4"},
                        {"name": "严重可疑费用占比","score": "4"},
                        {"name": "一般可疑费用占比","score": "4"}
                        ];
			}
			else if (code == 4) {
				return [
                        {"name": "住院个人负担比例","score": "15"},
                        {"name": "门诊个人负担比例","score": "15"}
                        ];
			}
			
		}
//		$scope.kpiSelectedDatas = [
//		                           {"name": "次均住院费用增长率","score": "1"},
//		                           {"name": "住院实际发生的统筹支付费用超支率（或总支付费用超支率）","score": "1"},
//		                           {"name": "平均住院日","score": "1"},
//		                           {"name": "平均床日费","score": "1"},
//		                           {"name": "次均住院费用","score": "1"},
//		                           {"name": "人均药品费用","score": "1"}
//		                           ];
		
	}]);
})();
